#include <bits/stdc++.h>
using namespace std;

class Solution
{
public:
    int maxOperations(vector<int>& nums, int k)
    {
        int ans = 0;
        int n = nums.size();
        unordered_map<int, int> mp;
        for (int i = 0; i < n; i++)
        {
            if (mp.find(k - nums[i]) != mp.end() &&
                mp[k - nums[i]] != 0)
            {
                mp[k - nums[i]]--;
                ans++;
            }
            else
            {
                mp[nums[i]]++;
            }
        }
        return ans;
    }
};
